import { createSlice } from '@reduxjs/toolkit';

export const HomeSlice = createSlice({
    name: 'HomeSlice',
    initialState: {
        pageContainerTabList: [
            {
                tab: '基础面板',
                key: '基础面板',
                path: '/home/controlpanel',
                closable: false,
            },
        ]
    },
    reducers: {
        addPageContainer: (state, action) => {
            let index = state.pageContainerTabList.findIndex(item => item.tab == action.payload.meta)
            if (index == -1) {
                state.pageContainerTabList.push({
                    tab: action.payload.meta,
                    key: action.payload.meta,
                    path: action.payload.path
                })
            }
        },
        delPageContainer: (state, actions) => {
            console.log(actions)
            let index = state.pageContainerTabList.findIndex(item => item.tab == actions.payload)
            state.pageContainerTabList.splice(index, 1)
        }
    }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { addPageContainer, delPageContainer, pageContainerTabList } = HomeSlice.actions

export default HomeSlice.reducer